package engine

import (
	"github.com/stretchr/testify/require"
	"testing"
)

var testTransitionQueryInfo = map[string]TransitionQueryInfo{
	"1828a670-5957-4bc5-9974-47da228f75e2": {
		QueryID:    "1828a670-5957-4bc5-9974-47da228f75e2",
		QueryName:  "Query3",
		Transition: 3,
	},
	"cf34805e-3872-4c08-bf92-6ff7bb0cfadb": {
		QueryID:    "cf34805e-3872-4c08-bf92-6ff7bb0cfadb",
		QueryName:  "Query5",
		Transition: 5,
	},
	"c3162390-7f18-4f31-8c73-da1d86c8a11e": {
		QueryID:    "c3162390-7f18-4f31-8c73-da1d86c8a11e",
		QueryName:  "Query1",
		Transition: 1,
	},
	"788996a7-4359-4568-9a91-1ad0c4112818": {
		QueryID:    "788996a7-4359-4568-9a91-1ad0c4112818",
		QueryName:  "Query2",
		Transition: 2,
	},
	"77f5d46e-7244-4606-80c6-18478627aa9e": {
		QueryID:    "77f5d46e-7244-4606-80c6-18478627aa9e",
		QueryName:  "Query4",
		Transition: 4,
	},
	"b9b7ada8-3868-4a35-854e-6100a2bb863d": {
		QueryID: "b9b7ada8-3868-4a35-854e-6100a2bb863d",
		QueryName: "Query6",
		Transition: 1,
	},
}

func TestCheckQueryTransitionType(t *testing.T) {

	tests := []struct {
		name         string
		changeID     string
		experimental bool
		expected     VulnerabilityBuilderTransition
	}{
		{
			name:         "Query with transition type 3 - AddedSearchValue ",
			changeID:     "1828a670-5957-4bc5-9974-47da228f75e2",
			experimental: false,
			expected:     AddedSearchValue,
		},
		{
			name:         "Query with transition type 5 - AddedSearchValueAndAddedSearchLine",
			changeID:     "cf34805e-3872-4c08-bf92-6ff7bb0cfadb",
			experimental: false,
			expected:     AddedSearchValueAndAddedSearchLine,
		},
		{
			name:         "Query with transition type 1 - NonGracefullyTransition",
			changeID:     "c3162390-7f18-4f31-8c73-da1d86c8a11e",
			experimental: false,
			expected:     NonGracefullyTransition,
		},
		{
			name:         "Query with transition type 2 - TransitionWithoutChanges",
			changeID:     "788996a7-4359-4568-9a91-1ad0c4112818",
			experimental: false,
			expected:     TransitionWithoutChanges,
		},
		{
			name:         "Query with transition type 4 - AddedSearchLine",
			changeID:     "77f5d46e-7244-4606-80c6-18478627aa9e",
			experimental: false,
			expected:     AddedSearchLine,
		},
		{
			name:     	  "Query with transition type 0 - YetToBeChecked",
			changeID:     "non-existing-query-id",
			experimental: false,
			expected:     YetToBeChecked,
		},
		{
			name:         "Query with transition type 1 - NonGracefullyTransition (experimental query)",
			changeID:     "b9b7ada8-3868-4a35-854e-6100a2bb863d",
			experimental: true,
			expected:     NonGracefullyTransition,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := checkQueryTransitionType(testTransitionQueryInfo, tt.changeID, tt.experimental)
			require.Equal(t, tt.expected, result)
		})
	}

}
